package com.example.user.controller;

import com.example.user.entity.User;
import com.example.user.reposity.UserReposity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;
import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserReposity userReposity;

    @GetMapping("/{id}")
    public User findById(@PathVariable long id){
//        User user = this.userReposity.findOne(id);
        User user = new User();
        user.setId(id);
        user.setName("mike");
        user.setAge(20);
        return user;
    }

    @GetMapping("/test")
    public String httpTest(HttpServletRequest request, HttpServletResponse response){
        StringBuilder builder = new StringBuilder();
        Enumeration<String> headers = request.getHeaderNames();
        while (headers.hasMoreElements()){
            String name = headers.nextElement();
            builder.append(name + "" + request.getHeader(name) + "\r\n");
            System.out.println(name + "" + request.getHeader(name));
        }
        return builder.toString();
    }
}
